package pl.edu.pw.elka.tinyrepo.gate.descriptor;


/**
 * Deskryptor pliku.
 * Plik w repozytorium jest jednoznacznie wyznaczany przez pare
 * (destination, id). 
 * 
 * @author Piotr Jarosik
 */
public class FileDescriptor implements Descriptor {
   /** ID pliku. Jest to unikalny klucz na serwerze danych destination. ID pliku 
    *  nie musi byc unikalne w skali repozytorium (ale para (destination, id) juz tak).*/
   private Integer id = 0;
   /** Serwer docelowy pliku. */
   private String destination = "";
   /** Rozmiar pliku. */
   private Long size = 0L;
   
   /**
    * Nalezy uzywac konstruktora dla id i rozmiaru
    * @param fileName
    */
   public FileDescriptor(Integer id, String destination, Long size) {
      super();
      this.id = id;
      this.destination = destination;
      this.size = size;
   }
   

   @Override
   public Long getSize() {
      return size;
   }
   
   @Override
   public synchronized void setSize(Long size) {
      this.size = size;
   }


   /**
    * @return the id
    */
   public Integer getId() {
      return id;
   }


   /**
    * @param id the id to set
    */
   public synchronized void setId(Integer id) {
      this.id = id;
   }


   /**
    * @return the destination
    */
   public String getDestination() {
      return destination;
   }


   /**
    * @param destination the destination to set
    */
   public synchronized void setDestination(String destination) {
      this.destination = destination;
   }
   
   /* (non-Javadoc)
    * @see java.lang.Object#hashCode()
    */
   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result
            + ((destination == null) ? 0 : destination.hashCode());
      result = prime * result + ((id == null) ? 0 : id.hashCode());
      return result;
   }


   /* (non-Javadoc)
    * @see java.lang.Object#equals(java.lang.Object)
    */
   @Override
   public boolean equals(Object obj) {
      if (this == obj)
         return true;
      if (obj == null)
         return false;
      if (getClass() != obj.getClass())
         return false;
      FileDescriptor other = (FileDescriptor) obj;
      if (destination == null) {
         if (other.destination != null)
            return false;
      } else if (!destination.equals(other.destination))
         return false;
      if (id == null) {
         if (other.id != null)
            return false;
      } else if (!id.equals(other.id))
         return false;
      return true;
   }

}
